package com.downbox.controller;

import com.downbox.dto.R;
import com.downbox.dto.UserInfoResp;
import com.downbox.dto.UserStatsResp;
import com.downbox.security.UserContext;
import com.downbox.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/user")
@Tag(name = "用户相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/info")
    @Operation(summary = "获取用户信息")
    public R<UserInfoResp> getUserInfo() {
        Long userId = UserContext.getUserId();
        UserInfoResp userInfo = userService.getUserInfo(userId);
        return R.success(userInfo);
    }

    @GetMapping("/stats")
    @Operation(summary = "获取用户统计信息")
    public R<UserStatsResp> getUserStats() {
        Long userId = UserContext.getUserId();
        UserStatsResp stats = userService.getUserStats(userId);
        return R.success(stats);
    }
    
    @PostMapping("/moods")
    @Operation(summary = "保存用户情绪")
    public R<Map<String, Boolean>> saveUserMoods(@RequestBody Map<String, List<String>> request) {
        Long userId = UserContext.getUserId();
        List<String> moods = request.get("moods");
        // 暂时返回成功
        Map<String, Boolean> response = new HashMap<>();
        response.put("saved", true);
        return R.success(response);
    }
    
    @PostMapping("/update")
    @Operation(summary = "更新用户信息")
    public R<Map<String, Boolean>> updateUserInfo(@RequestBody Map<String, Object> request) {
        Long userId = UserContext.getUserId();
        // 暂时返回成功
        Map<String, Boolean> response = new HashMap<>();
        response.put("updated", true);
        return R.success(response);
    }
}